﻿#pragma once

#include <drogon/HttpController.h>
#include "OCServer/DocGenerate.h"
using namespace drogon;
using namespace OCPP;

class MyDoc
{
public:
	static void doc(const HttpRequestPtr& req,
		std::function<void(const HttpResponsePtr&)>&& callback,String queryapi)
	{
		String docClass = "WeatherService";
		if (queryapi == "")
		{
			auto resp = drogon::HttpResponse::newRedirectionResponse("/swagger/index.html?s=" + docClass);
			callback(resp);
		}
		else if (queryapi == "api")
		{
			static String body;
			if (body.empty())
			{
				Date startTime = Date::now().roundDay();

				OpenApiDoc doc;
				doc.setBaseUrl("/" + docClass);

				doc.addMethod().setPath("/gfs/getFile").setDescription("获取文件")
					.addParameter("time", "开始时间", "query", "string", startTime.toDbString())
					.addParameter("var", "结束时间", "query", "string", "Temperature_height_above_ground")
					.addParameter("level", "高度层", "query", "string", "10m");

				doc.addMethod().setPath("/gfs/getTimeList").setDescription("获取时间列表")
					.addParameter("startTime", "开始时间", "query", "string", startTime.toDbString())
					.addParameter("endTime", "结束时间", "query", "string", startTime.after(86400).toDbString());
				body = doc.toString();
			}
			HttpResponsePtr resp = HttpResponse::newHttpResponse();
			resp->setBody(body);
			resp->setContentTypeCode(drogon::ContentType::CT_APPLICATION_JSON);
			callback(resp);
		}
		else
		{
			auto resp = HttpResponse::newNotFoundResponse();
			callback(resp);
		}
	}
};

